<?php
	function __construct(){
		require './model/type_model.php';
		$_GET['a']();
	}
	function index(){
		$ret = getTypeInfo();
		require './view/type/index.php';
	}
	
	function addFrom(){
		require './view/type/addFrom.php';
	}
	
	function doadd(){
		if(insert()){
			echo '插入成功!';
			echo '<meta http-equiv="refresh" content="0;./index.php?c=type&a=index" />';
		}else{
			echo '插入失败!';
			echo '<meta http-equiv="refresh" content="2;./index.php?c=type&a=index" />';
		}
	}
	
	function edit(){
		$ret = select(" WHERE tid = $_GET[id]")[0];
		$pname = select(" WHERE tid = $ret[pid]")[0]['tname'];
		require './view/type/edit.php';
	}
	function doedit(){
		if(update()){
			echo '<meta http-equiv="refresh" content="0;./index.php?c=type&a=index" />';
		}else{
			echo '修改失败!';
			echo '<meta http-equiv="refresh" content="2;./index.php?c=type&a=index" />';
		}
	}
	function del(){
		$_GET['tblname'] = 'shop_goods';
			$_GET['pk'] = 'gid';
			if(select(" WHERE tid = '$_GET[id]'")){
				echo '有商品,不允许删除!';
				echo '<meta http-equiv="refresh" content="2;./index.php?c=type&a=index" />';
			}else{
				$_GET['tblname'] = 'shop_type';
				$_GET['pk'] = 'tid';
				if(select(" WHERE pid = '$_GET[id]'")){
					echo '有子类,不允许删除!';
					echo '<meta http-equiv="refresh" content="2;./index.php?c=type&a=index" />';
				}else{
					if(delete()){
						echo '删除成功!';
						echo '<meta http-equiv="refresh" content="0;./index.php?c=type&a=index" />';
					}else{
						echo '删除失败!';
						echo '<meta http-equiv="refresh" content="2;./index.php?c=type&a=index" />';
					}
				}
		}
	}